#! /bin/sh -vx
# $Id$
# Copyright 2017 Karl Berry <tex-live@tug.org>
# Copyright 2011, 2012 Peter Breitenlohner <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_tftopl=tftopl$ExeExt
_pktype=pktype$ExeExt
_ttf2tfm=$BinDir/ttf2tfm$ExeExt
_ttf2pk=$BinDir/ttf2pk$ExeExt

# pre-generated test results in the repository are stored in LF
# but the output might be written in CRLF on some platform.
# if 'diff --strip-trailing-cr' is available, exploit it.
# (useful for tests on win32 binaries run on MSYS shell)
DIFF="diff"
$DIFF --strip-trailing-cr $0 $0 \
  && DIFF="diff --strip-trailing-cr" || echo

rc=0

rm -f GenR-ec.vpl GenR102-* ipaexg-*

TEXMFCNF=$srcdir/../kpathsea
TEXFONTS=".;$srcdir/tests"
TTF2PKINPUTS=$srcdir/tests
SFDFONTS="$srcdir/data;$srcdir/tests"
PATH=../web2c:$PATH

export TEXMFCNF TEXFONTS TTF2PKINPUTS SFDFONTS PATH

$_ttf2tfm GenR102 -u -q -N -T gentium-ec -v GenR-ec GenR102-ec >GenR102-ec.map || rc=1
$DIFF $srcdir/tests/GenR102-ec.map GenR102-ec.map || rc=2
$DIFF $srcdir/tests/GenR-ec.vpl GenR-ec.vpl || rc=3

$_ttf2pk -q GenR102-ec 100 || rc=4

$_tftopl GenR102-ec GenR102-ec || exit 77
diff $srcdir/tests/GenR102-ec.pl GenR102-ec.pl || rc=5
$_pktype GenR102-ec.100pk >GenR102-ec.typ || exit 77

echo passed GenR102-ec test

$_ttf2tfm GenR102 -q GenR102-h@UBig5@ >GenR102-h.map || rc=6
$DIFF $srcdir/tests/GenR102-h.map GenR102-h.map || rc=7

for sf in 00 01 02 24; do

  $_ttf2pk -q GenR102-h$sf 100 || rc=8

  $_tftopl GenR102-h$sf GenR102-h$sf || exit 77
  $_pktype GenR102-h$sf.100pk >GenR102-h$sf.typ || exit 77

done

echo passed GenR102-h test

$_ttf2tfm GenR102 -q -x GenR102-v@UBig5@ >GenR102-v.map || rc=9
$DIFF $srcdir/tests/GenR102-v.map GenR102-v.map || rc=10

for sf in 00 01 02 24; do

  $_ttf2pk -q GenR102-v$sf 100 || rc=11

  $_tftopl GenR102-v$sf GenR102-v$sf || exit 77
  $_pktype GenR102-v$sf.100pk >GenR102-v$sf.typ || exit 77

done

echo passed GenR102-v test

$_ttf2tfm ipaexg -q ipaexg-h@Test@ >ipaexg-h.map || rc=12
$DIFF $srcdir/tests/ipaexg-h.map ipaexg-h.map || rc=13

$_ttf2pk -q ipaexg-h03 100 || rc=14

$_tftopl ipaexg-h03 ipaexg-h03  || exit 77
diff $srcdir/tests/ipaexg-h03.pl ipaexg-h03.pl || rc=15
$_pktype ipaexg-h03.100pk >ipaexg-h03.typ || exit 77

echo passed ipaexg-h test

$_ttf2tfm ipaexg -q -x ipaexg-v@Test@ >ipaexg-v.map || rc=16
$DIFF $srcdir/tests/ipaexg-v.map ipaexg-v.map || rc=17

$_ttf2pk -q ipaexg-v03 100 || rc=18

$_tftopl ipaexg-v03 ipaexg-v03  || exit 77
diff $srcdir/tests/ipaexg-v03.pl ipaexg-v03.pl || rc=19
$_pktype ipaexg-v03.100pk >ipaexg-v03.typ || exit 77

echo passed ipaexg-v test

exit $rc
